package thread;

public class TestThreadLocal {
    public static int count = 0;
    public static final ThreadLocal<Integer> nums = new InheritableThreadLocal<>();
    public static void main(String[] args) {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                nums.set(count);
                for (int i = 0; i < 1000; i++) {
                    nums.set(nums.get()+1);
                    System.out.println("t1-------------"+nums.get());
                }
            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                nums.set(count);
                for (int i = 0; i < 1000; i++) {
                    nums.set(nums.get()+1);
                    System.out.println("t2-------------"+nums.get());
                }
            }
        });
        t1.start();
        t2.start();
    }

}
